﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BaseCardTypes = Wormhole.Engine.CardLibrary.BaseCardTypes;

namespace Wormhole.UI.Application.Controls.Mission
{
	/// <author>Hannes Foulds</author>
	/// <date>23 June 2008</date>
	/// <summary>
	/// Display a failed mission card.
	/// </summary>
	public class FailedMission : Controls.Cards.Card
	{
		#region Constructor
		public FailedMission() : base()
		{
		}

		public FailedMission(BaseCardTypes.Card card)
			: base(card)
		{
		}
		#endregion

		#region Set Size
		/// <summary>
		/// Set the card size.
		/// </summary>
		protected override void SetSize()
		{
			this.cardImage.Width = 313 * .2;
			this.cardImage.Height = 217 * .2;
			this.cardImage.Stretch = Stretch.Fill;

			this.outsideBorder.Width = this.cardImage.Width + 4;
			this.outsideBorder.Height = this.cardImage.Height + 4;

			this.Width = this.outsideBorder.Width;
			this.Height = this.outsideBorder.Height;
		}
		#endregion

		#region Display Image
		/// <summary>
		/// Display the card image.
		/// </summary>
		protected override void DisplayImage()
		{
			// get the drawing context
			DrawingVisual drawingVisual = new DrawingVisual();
			DrawingContext drawingContext = drawingVisual.RenderOpen();

			// draw the card image
			drawingContext.DrawImage(this.imageSource, new Rect(0, 0, this.imageSource.Width, this.imageSource.Height));

			// create the skills font type
			Typeface baseFont = new Typeface("Veranda");
			Typeface skillsFont = new Typeface(baseFont.FontFamily, FontStyles.Normal, FontWeights.Bold, FontStretches.Normal);

			Brush brush = new SolidColorBrush(Colors.Red);
			brush.Opacity = 0.9;

			// draw the text
			drawingContext.DrawText(
				   new FormattedText("FAILED",
					  CultureInfo.GetCultureInfo("en-us"),
					  FlowDirection.LeftToRight,
					  skillsFont,
					  60, brush),
					  new Point(10, 0));

			// get the image source
			drawingContext.Close();
			RenderTargetBitmap targetBitmap = new RenderTargetBitmap(this.imageSource.PixelWidth, this.imageSource.PixelHeight, 96, 96, PixelFormats.Pbgra32);
			targetBitmap.Render(drawingVisual);

			// assign the image source
			this.cardImage.Source = targetBitmap;
		}
		#endregion
	}
}
